﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.Phone.Controls;
using Moneyman.DataModel;
using System.Linq;
using Moneyman.Enums;

namespace Moneyman.ViewModel
{
    public class MainViewModel : ViewModelBase
    {
        public Uri BackUri
        {
            get
            {
                PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
                PhoneApplicationPage page = (PhoneApplicationPage)frame.Content;
                if (page.Tag != null)
                {
                    return (Uri)page.Tag;
                }
                return null;
            }
        }

        #region CommonCollections
        public IEnumerable<CategoryInfo> CommonCategoryCollection
        {
            get
            {
                if (Database.CollectionOfCategories.Count() == 0)
                {
                    Database.CollectionOfCategories.InsertOnSubmit(new CategoryInfo() { Kind = TransactionKindValue.Income, IconResourceKey = "PATH_CATE_DEFAULT", Name = "默认" });
                    Database.CollectionOfCategories.InsertOnSubmit(new CategoryInfo() { Kind = TransactionKindValue.Expense, IconResourceKey = "PATH_CATE_DEFAULT", Name = "默认" });
                    Execute();
                }
                return Database.CollectionOfCategories;
            }
        }

        public IEnumerable<CaseInfo> CommonCaseCollection
        {
            get
            {
                return Database.CollectionOfCases;
            }
        }

        public IEnumerable<PlaceInfo> CommonPlaceCollection
        {
            get
            {
                return Database.CollectionOfPlaces;
            }
        }
        #endregion
    }
}
